var urltest = sessionStorage.getItem("urltest");
var userId = sessionStorage.getItem("userId");
var userName = sessionStorage.getItem("userName");
var fullname = sessionStorage.getItem("fullname");

$(function() {
	if(userId == "" || userId == undefined || userId == null) {
		//		alert("请登陆之后再操作");
		top.location.href = "login.html";
	} else {
		//		debugger
		userId = userId;
		var pageNumber = "1";
		var pageSize = "10";
		//		var startday = "";
		//		var endday = "";
		var selectinfo = "";
		//	var userId = "";
		var reque = function() {
			return {
				pageSize: pageSize,
				pageNumber: pageNumber,
				selectinfo: selectinfo,
			}
		}
		rq1 = reque();
		var req = function() {
			return {
				requestString: "",
				userId: userId,
				fullname: fullname
			}
		}
		requestObj1 = req();
		requestObj1.requestString = JSON.stringify(rq1);
		var req3 = JSON.stringify(requestObj1);
		$.ajax({
			contentType: "application/json; charset=utf-8",
			type: "POST",
			url: urltest + 'verify/property/selectPropertyPayInfoList',
			data: req3,
			async: false,
			dataType: "json",
			success: function(msg) {
				console.log(msg);
				if(msg.responseCode == 200) {

					$("#count").html(msg.count);
					var gezi = msg.count;
					if(gezi % 10 == 0) {
						var lenn = parseInt(gezi / 10);
						if(lenn == 0) {
							var lenn = 1;
						}
					} else {
						var lenn = parseInt(gezi / 10) + 1;
					}
					test("Test bootstrap v3 rendering", function() {
						var element = $('#bp-3-element-test');
						var options = {
							bootstrapMajorVersion: 3,
							currentPage: 1,
							numberOfPages: 5,
							totalPages: lenn
						}
						element.bootstrapPaginator(options);
						var element = $('#bp-3-element-test');
						ok(!element.hasClass('pagination-lg'), "Root element shouldn't have pagination-lg class");
						ok(!element.hasClass('pagination-sm'), "Root element shouldn't have pagination-sm class");
						var list = element.children();
						for(var i = 0; i < list.length; i++) {
							var item = $(list[i]);
							ok(item.is("li"), "Element " + i + " should be li");
						}
					});
					var table_msg = msg.returnString;
					createShowingTable(table_msg);
				} else {
					alert(msg.resoponseDisp)
				}
			},
			error: function() {
				alert("获取信息失败");
			}
		});
	}

});

$("#bp-3-element-test").on("click", function() {
	var aa = $(this).children(".active").children("a").html();
	var pageNumber = aa;
	var pageSize = "10";
	//	var star_time = $('.input_1').val();
	//	var end_time = $('.input_2').val();
	var search_main = $('#text_sousuo').val();
	//	var startday = star_time;
	//	var endday = end_time;
	var selectinfo = search_main;
	//	var userId = "";
	var reque = function() {
		return {
			pageSize: pageSize,
			pageNumber: pageNumber,
			selectinfo: selectinfo
		}
	}
	rq1 = reque();
	var req = function() {
		return {
			requestString: "",
			userId: userId,
			fullname: fullname
		}
	}
	requestObj1 = req();
	requestObj1.requestString = JSON.stringify(rq1);
	var req3 = JSON.stringify(requestObj1);

	$.ajax({
		contentType: "application/json; charset=utf-8",
		type: "POST",
		url: urltest + 'verify/property/selectPropertyPayInfoList',
		data: req3,
		async: true,
		dataType: "json",
		success: function(msg) {
			console.log(msg);
			if(msg.responseCode == 200) {
				console.log(msg);
				$("#count").html(msg.count);
				var gezi = msg.count;
				if(gezi % 10 == 0) {
					var lenn = parseInt(gezi / 10);
					if(lenn == 0) {
						var lenn = 1;
					}
				} else {
					var lenn = parseInt(gezi / 10) + 1;
				}
				test("Test bootstrap v3 rendering", function() {
					var element = $('#bp-3-element-test');
					var options = {
						bootstrapMajorVersion: 3,
						currentPage: aa,
						numberOfPages: 5,
						totalPages: lenn
					}
					element.bootstrapPaginator(options);
					var element = $('#bp-3-element-test');
					ok(!element.hasClass('pagination-lg'), "Root element shouldn't have pagination-lg class");
					ok(!element.hasClass('pagination-sm'), "Root element shouldn't have pagination-sm class");
					var list = element.children();
					for(var i = 0; i < list.length; i++) {
						var item = $(list[i]);
						ok(item.is("li"), "Element " + i + " should be li");
					}
				});
				var table_msg = msg.returnString;
				createShowingTable(table_msg);
			} else {
				alert(msg.resoponseDisp)
			}
		},
		error: function() {
			alert("获取信息失败");
		}
	});

})

function createShowingTable(bb) {
	//	debugger
	//获取后台传过来的jsonData,并进行解析  
	//此处需要让其动态的生成一个table并填充数据 
	if(bb.total == 0) {
		$("#tbbb").html("");
	} else {
		console.log(bb);
		var bb = JSON.parse(bb);
		var tableStr = "";
		var len = bb.list.length;
		if(len == 0) {
			var wuxiaoxi = '<p>' + "暂无内容" + '</p>'
			$("#tbbb").html(wuxiaoxi);
		} else {
			for(var i = 0; i < len; i++) {
				//				0 未支付 1 已支付 2 已取消
				//				3 已退款 4 缴费失败， 已退款
				if(bb.list[i].propertyname == undefined) {
					bb.list[i].propertyname = '';
				}
				if(bb.list[i].propertyid == undefined) {
					bb.list[i].propertyid = '';
				}
				if(bb.list[i].createdate == undefined) {
					bb[i].createdate = '';
				}
				if(bb.list[i].createusername == undefined) {
					bb.list[i].createusername = '';
				}
				var num = parseInt(i) + parseInt(1);
				tableStr = tableStr + '<tr>' +
					'<th>' + num + '</th>' +
					'<th>' + bb.list[i].propertyname + '</th>' +
					'<th>' + bb.list[i].propertyid + '</th>' +
					'<th>' + bb.list[i].createdate + '</th>' +
					'<th>' + bb.list[i].createusername + '</th>' +
					'<th style="display: none;">' + bb.list[i].id + '</th>' + //id								
					'<th  data-toggle="modal" data-target="#myModal"  style="color:blue;cursor: pointer" ;><span class="glyphicon glyphicon-edit"></span></th>' +
					'</tr>';
			}
			//将动态生成的table添加的事先隐藏的div中.  
			$("#tbbb").html(tableStr);

		}

		//点击详情
		$("#tbbb tr th:nth-child(7)").click(function() {
			//			debugger

			//			var str = "   fewfe    ";
			//			var str1 = $.trim(str)
			//			console.log(str1)
			var dateee = $(this).siblings().eq(3).html();
			var id = $(this).siblings().eq(5).html();
			var reque = function() {
				return {
					id: id,
				}
			}
			rq1 = reque();
			var req = function() {
				return {
					requestString: "",
					userId: userId,
					fullname: fullname
				}
			}
			requestObj1 = req();
			requestObj1.requestString = JSON.stringify(rq1);
			var req3 = JSON.stringify(requestObj1);
			//查看某一服务商详情
			$.ajax({
				contentType: "application/json; charset=utf-8",
				type: "POST",
				url: urltest + 'verify/property/selectPropertyPayInfo',
				data: req3,
				async: true,
				dataType: "json",
				success: function(msg) {
					console.log(msg);
					if(msg.responseCode == 200) {
						console.log(msg);
						var bb = JSON.parse(msg.returnString);

						$("#wy_f_wym").html(bb.propertyname);
						$("#wy_f_id").html(bb.id);
						$("#wy_f_wyid").html(bb.propertyid);
						$("#wy_f_cjsj").html(dateee);
						$("#wy_f_cjrid").html(bb.createuserid);
						$("#wy_f_cjrmz").html(bb.createusername);

						$("#wy_f_zfbappid").val(bb.alipayAppid);
						$("#wy_f_wxzshappid").val(bb.subAppid);
						$("#wy_f_wxzshh").val(bb.subMchId);
						$("#wy_f_zfbgy").val(bb.alipayPayPublic);
						$("#wy_f_yysy").val(bb.privateKey);
						$("#wy_f_yygy").val(bb.publicKey);

					} else {
						alert(msg.resoponseDisp)
					}
				},
				error: function() {
					alert("获取信息失败");
				}
			});

		});

	}
}

//模糊查询
$('#search_chaxun').click(function() {
	var pageNumber = "1";
	var pageSize = "10";
	//	var auditstatus = "1";
	//	var pp = $("#select_type").val();
	//	var star_time = $('.input_1').val();
	//	var end_time = $('.input_2').val();

	var search_main = $('#text_sousuo').val();
	//	var startday = star_time;
	//	var endday = end_time;
	var selectinfo = search_main;

	//	var userId = "";
	var reque = function() {
		return {
			pageSize: pageSize,
			pageNumber: pageNumber,

			selectinfo: selectinfo,

		}
	}
	rq1 = reque();
	var req = function() {
		return {
			requestString: "",
			userId: userId,
			fullname: fullname
		}
	}
	requestObj1 = req();
	requestObj1.requestString = JSON.stringify(rq1);
	var req3 = JSON.stringify(requestObj1);
	//	console.log(star_time+end_time+search_main)
	$.ajax({
		contentType: "application/json; charset=utf-8",
		type: "POST",
		url: urltest + 'verify/property/selectPropertyPayInfoList',
		data: req3,
		async: true,
		dataType: "json",
		success: function(msg) {
			console.log(msg);
			if(msg.responseCode == 200) {
				$("#count").html(msg.count);
				var gezi = msg.count;
				if(gezi % 10 == 0) {
					var lenn = parseInt(gezi / 10);
					if(lenn == 0) {
						var lenn = 1;
					}
				} else {
					var lenn = parseInt(gezi / 10) + 1;
				}
				test("Test bootstrap v3 rendering", function() {
					var element = $('#bp-3-element-test');
					var options = {
						bootstrapMajorVersion: 3,
						currentPage: 1,
						numberOfPages: 5,
						totalPages: lenn
					}
					element.bootstrapPaginator(options);
					var element = $('#bp-3-element-test');
					ok(!element.hasClass('pagination-lg'), "Root element shouldn't have pagination-lg class");
					ok(!element.hasClass('pagination-sm'), "Root element shouldn't have pagination-sm class");
					var list = element.children();
					for(var i = 0; i < list.length; i++) {
						var item = $(list[i]);
						ok(item.is("li"), "Element " + i + " should be li");
					}
				});
				var table_msg = msg.returnString;
				createShowingTable(table_msg);
			} else {
				alert(msg.resoponseDisp)
			}
		},
		error: function() {
			alert("获取信息失败");
		}
	});

})
//获取物业名字
$("#wuye_add_zhifu").click(function() {
	var reque = function() {
		return {
			parentid: "",
		}
	}
	rq1 = reque();
	var req = function() {
		return {
			requestString: "",
			userId: userId,
			fullname: fullname
		}
	}
	requestObj1 = req();
	requestObj1.requestString = JSON.stringify(rq1);
	var req3 = JSON.stringify(requestObj1);
	$.ajax({
		contentType: "application/json; charset=utf-8",
		type: "POST",
		url: urltest + 'verify/property/selectOrganizeNameList',
		data: req3,
		async: true,
		dataType: "json",
		success: function(msg) {
			console.log(msg);
			if(msg.responseCode == 200) {
				console.log(msg);
				console.log(msg.returnString);
				var bb = JSON.parse(msg.returnString);
				//				var str = "";
				var str = '<option value="0">' + "请选择物业名称" + '</option>';
				for(var i = 0; i < bb.length; i++) {
					str += "<option value=" + bb[i].organizeid + ">" + bb[i].shortname + "</option>";
				}
				$("#wy_wymz").html("");
				$("#wy_wymz").append(str);
			} else {
				alert(msg.resoponseDisp)
			}
		},
		error: function() {
			alert("获取信息失败");
		}
	});
})

//添加物业支付信息
$(".wuzf_add").click(function() {
	//	debugger	String str2 = str.replaceAll(" ", "");  
	var propertyid = $.trim($("#wy_wymz ").val());
	var propertyname = $.trim($("#wy_wymz option:selected").text());
	var alipayAppid = $.trim($("#wy_appid ").val());
	var alipayPayPublic = $.trim($("#wy_zfbgy ").val());
	var privateKey = $.trim($("#wy_yysy ").val());
	var publicKey = $.trim($("#wy_yygy ").val());
	var subAppid = $.trim($("#wy_wxzshappid ").val());
	var subMchId = $.trim($("#wy_wxzshh ").val());
	if(propertyid != 0 && alipayAppid != "" && alipayPayPublic != "" && privateKey != "" && subAppid != "" && subMchId != "" && publicKey != "") {
		var reque = function() {
			return {
				propertyid: propertyid,
				propertyname: propertyname,
				alipayAppid: alipayAppid,
				alipayPayPublic: alipayPayPublic,
				privateKey: privateKey,
				publicKey: publicKey,
				subAppid: subAppid,
				subMchId: subMchId,
				createuserid: userId,
				createusername: userName
			}
		}
		rq1 = reque();
		var req = function() {
			return {
				requestString: "",
				userId: userId,
				fullname: fullname
			}
		}
		requestObj1 = req();
		requestObj1.requestString = JSON.stringify(rq1);
		var req3 = JSON.stringify(requestObj1);
		$.ajax({
			contentType: "application/json; charset=utf-8",
			type: "POST",
			url: urltest + 'verify/property/addPropertyPayInfo',
			data: req3,
			async: true,
			dataType: "json",
			success: function(msg) {
				console.log(msg);
				if(msg.responseCode == 200) {
					alert("添加成功！")
					location.href = "wuyezhifu_in.html"
				} else {
					alert(msg.resoponseDisp)
				}
			},
			error: function() {
				alert("获取信息失败");
			}
		});
	} else {
		alert("请确定每项数据都已经填写！");

	}

})
//删除
$(".remove").click(function() {
	var id = $("#wy_f_id").html();

	var reque = function() {
		return {
			id: id,
			deleteuser: userId,
			deleteusername: userName
		}
	}
	rq1 = reque();
	var req = function() {
		return {
			requestString: "",
			userId: userId,
			fullname: fullname
		}
	}
	requestObj1 = req();
	requestObj1.requestString = JSON.stringify(rq1);
	var req3 = JSON.stringify(requestObj1);
	$.ajax({
		contentType: "application/json; charset=utf-8",
		type: "POST",
		url: urltest + 'verify/property/deletePropertyPayinfo',
		data: req3,
		async: true,
		dataType: "json",
		success: function(msg) {
			console.log(msg);
			if(msg.responseCode == 200) {
				alert("删除成功！")
				location.href = "wuyezhifu_in.html"
			} else {
				alert(msg.resoponseDisp)
			}
		},
		error: function() {
			alert("获取信息失败");
		}
	});
})

//修改
$('.fix_wyzf').click(function() {
	debugger
	var id = $("#wy_f_id").html();
	var alipayAppid = $.trim($("#wy_f_zfbappid ").val());
	var alipayPayPublic = $.trim($("#wy_f_zfbgy").val());
	var privateKey = $.trim($("#wy_f_yysy ").val());
	var publicKey = $.trim($("#wy_f_yygy ").val());
	var subAppid = $.trim($("#wy_f_wxzshappid ").val());
	var subMchId = $.trim($("#wy_f_wxzshh ").val());
	if(alipayAppid != "" && alipayPayPublic != "" && privateKey != "" && subAppid != "" && subMchId != "" && publicKey != "") {
		var reque = function() {
			return {
				id: id,
				alipayAppid: alipayAppid,
				alipayPayPublic: alipayPayPublic,
				privateKey: privateKey,
				publicKey: publicKey,
				subAppid: subAppid,
				subMchId: subMchId,
				modifyuserid: userId,
				modifyusername: userName
			}
		}
		rq1 = reque();
		var req = function() {
			return {
				requestString: "",
				userId: userId,
				fullname: fullname
			}
		}
		requestObj1 = req();
		requestObj1.requestString = JSON.stringify(rq1);
		var req3 = JSON.stringify(requestObj1);
		$.ajax({
			contentType: "application/json; charset=utf-8",
			type: "POST",
			url: urltest + 'verify/property/updatePropertyPayinfo',
			data: req3,
			async: true,
			dataType: "json",
			success: function(msg) {
				console.log(msg);
				if(msg.responseCode == 200) {
					alert("修改成功！")
					location.href = "wuyezhifu_in.html"
				} else {
					alert(msg.resoponseDisp)
				}
			},
			error: function() {
				alert("获取信息失败");
			}
		});
	} else {
		alert("请确定每项数据都已经填写！");

	}
})